package com.oneday.ashop.console.base.spring;

import com.oneday.ashop.console.base.shiro.filter.BaseResourceFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * 用于spring容器加载之后初始化一些数据
 * Created by admin on 2016/7/6.
 */
@Slf4j
@Component
public class BaseApplicationListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private BaseResourceFilter baseResourceFilter;

    //容器加载之后出发事件调用的方法
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
       if(contextRefreshedEvent.getApplicationContext().getParent() == null) {//root application context 没有parent，他就是老大.
           //初始化
           baseResourceFilter.init();
       }
    }
}
